package bank.soap;

import java.io.IOException;

import bank.Account;
import bank.InactiveException;
import bank.OverdrawException;
import bank.soap.client.BankServiceImpl;
import bank.soap.client.IOException_Exception;
import bank.soap.client.IllegalArgumentException_Exception;
import bank.soap.client.InactiveException_Exception;
import bank.soap.client.OverdrawException_Exception;

public class SOAPAccount implements Account{

	private BankServiceImpl port;

	private String number;

	public SOAPAccount(BankServiceImpl port, String number) {
		this.port = port;
		this.number = number;
	}
	
	public String getNumber() throws IOException {
		return number;
	}

	public String getOwner() throws IOException {
		try {
			return port.getOwner(number);
		} catch (IOException_Exception e) {
			e.printStackTrace();
		}
		return number;
	}

	public boolean isActive() throws IOException {
		try {
			return port.isActive(number);
		} catch (IOException_Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public void deposit(double amount) throws IOException, IllegalArgumentException, InactiveException {
		try {
			port.deposit(number, amount);
		} catch (IOException_Exception e) {
			e.printStackTrace();
		} catch (IllegalArgumentException_Exception e) {
			e.printStackTrace();
		} catch (InactiveException_Exception e) {
			e.printStackTrace();
		}
	}
	
	public void withdraw(double amount) throws IOException, IllegalArgumentException, OverdrawException, InactiveException {
		try {
			port.withdraw(number, amount);
		} catch (IOException_Exception e) {
			e.printStackTrace();
		} catch (IllegalArgumentException_Exception e) {
			e.printStackTrace();
		} catch (InactiveException_Exception e) {
			e.printStackTrace();
		} catch (OverdrawException_Exception e) {
			e.printStackTrace();
		}
	}
	
	public double getBalance() throws IOException {
		try {
			return port.getBalance(number);
		} catch (IOException_Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
}
